package com.example.service.Imp;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.b_pojo.Musiccategory;
import com.example.common.utils.Resultb;
import com.example.dao.mapper.BMusiccategoryMapper;
import com.example.service.BMusicCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@Transactional
public class BMusicCategoryServiceImp implements BMusicCategoryService {

    @Autowired
    private BMusiccategoryMapper bmusiccategoryMapper;

    @Override
    public Page<Musiccategory> alllist(int pageNum, int pageSize) {
        Page<Musiccategory> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<Musiccategory> queryWrapper = new LambdaQueryWrapper<>();
        Page<Musiccategory> page1=bmusiccategoryMapper.selectAllCategory(page, queryWrapper);
        if(page.getTotal()>0){
            return page1;
        }else{
            return null;
        }
    }

    @Override
    public Page<Musiccategory> hasdelectlist(int pageNum, int pageSize) {
        Page<Musiccategory> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<Musiccategory> queryWrapper = new LambdaQueryWrapper<>();
        Page<Musiccategory> musiccategoryPage = bmusiccategoryMapper.selectPage(page, queryWrapper);
        return musiccategoryPage;
    }

    @Override
    public Musiccategory getcategoryById(Long id) {
        Musiccategory musiccategory = bmusiccategoryMapper.selectById(id);
        if(musiccategory!=null){
            return musiccategory;
        }
        return null;
    }

    @Override
    public List<Musiccategory> getcategoryByName(String categoryName) {
        List<Musiccategory> musiccategoryList=bmusiccategoryMapper.selectLikeByName(categoryName);
        if(musiccategoryList!=null){
            return musiccategoryList;
        }
        return null;
    }

    @Override
    public boolean insertcategory(Musiccategory musiccategory) {
        boolean insert = bmusiccategoryMapper.insert(musiccategory) >0;
        return insert;
    }

    @Override
    public boolean updateById(Musiccategory musiccategory) {
        boolean update = bmusiccategoryMapper.updateById(musiccategory) >0;
        return update;
    }

    @Override
    public boolean startandstopcategory(Long id) {
        int i=bmusiccategoryMapper.startandstopcategory(id);
        if(i>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean removeById(Long id) {
        boolean removeById = bmusiccategoryMapper.deleteallById(id) >0;
        if(removeById){
            return true;
        }
        return false;
    }

}
